const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        order: [
            {
                id: "01",
                src: "img/order_icon1.png",
                text: "待付款",
                num: "2"
            },
            {
                src: "img/order_icon2.png",
                text: "待发货",
                num: "5"
            },
            {
                src: "img/order_icon3.png",
                text: "已发货",
                num: "7"
            },
            {
                src: "img/order_icon4.png",
                text: "退款",
                num: "8"
            }
        ],
        list1: [
            {
                id: "01",
                src: "img/list_icon1.png",
                text: "我参与的活动",
                num: "4"
            },
            {
                id: "02",
                src: "img/list_icon2.png",
                text: "邀请好友",
                num: "5"
            }
        ],
        list2: [
            {
                id: "01",
                src: "img/list_icon4.png",
                text: "我的卡券"
            },
            {
                id: "02",
                src: "img/list_icon3.png",
                text: "齐乐豆"
            },
            {
                id: "03",
                src: "img/list_icon5.png",
                text: "我的消息"
            },
            {
                id: "04",
                src: "img/list_icon6.png",
                text: "帮助中心"
            }
        ],
    },
    onLoad: function () {
        if (app.globalData.userInfo) {
            this.setData({
                userInfo: app.globalData.userInfo,
                hasUserInfo: true
            })
        } else if (this.data.canIUse) {
            // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
            // 所以此处加入 callback 以防止这种情况
            app.userInfoReadyCallback = res => {
                this.setData({
                    userInfo: res.userInfo,
                    hasUserInfo: true
                })
            }
        } else {
            // 在没有 open-type=getUserInfo 版本的兼容处理
            wx.getUserInfo({
                success: res => {
                    app.globalData.userInfo = res.userInfo
                    this.setData({
                        userInfo: res.userInfo,
                        hasUserInfo: true
                    })
                }
            })
        }
    },
    getUserInfo: function (e) {
        console.log(e)
        app.globalData.userInfo = e.detail.userInfo
        this.setData({
            userInfo: e.detail.userInfo,
            hasUserInfo: true
        })
    },
    //事件处理函数
    bindList: function () {
        wx.navigateTo({
            url: '../personal_list/index'
        })
    },
    order: function () {
        wx.navigateTo({
            url: '../order/index'
        })
    },
    listing1: function (e) {
        var index = e.target.id  /*获取ID索引 */
        if (index == "01") {
            wx.navigateTo({
                url: '../personal_activity/index'
            })
        } else if (index == "02") {
            wx.navigateTo({
                url: '../personal_generalize/index'
            })
        }
    },
    listing2: function (e) {
        var index = e.target.id  /*获取ID索引 */
        if (index == "01") {
            wx.navigateTo({
                url: '../personal_discount/index'
            })
        } else if (index == "02") {
            wx.navigateTo({
                url: '../personal_recharge/index'
            })
        } else if (index == "03") {
            wx.navigateTo({
                url: '../personal_news/index'
            })
        } else if (index == "04") {
            wx.navigateTo({
                url: '../personal_help/index'
            })
        }
    }
})